package com.atguigu.practice;

import java.util.Scanner;

public class TheMaxSubArraySum {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] array=new int[n];
        for(int i=0;i<n;i++){
            array[i]=scanner.nextInt();
        }
        int tmp=0;
        int max=0;
        for(int i=0;i<n;i++){
            tmp+=array[i];
            if(tmp>max){
                max=tmp;
            }else if(tmp<0){
                tmp=0;
            }
        }
        System.out.println(max);
    }
}
